# 121. 买卖股票的最佳时机
# https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/
class Solution:
    def maxProfit(self, prices):
        if len(prices) < 2:
            return 0
        min_p, max_out = prices[0], 0
        for p in prices:
            max_out = max(p - min_p, max_out)
            min_p = min(p, min_p)
        return max_out

print(Solution().maxProfit([7,1,5,3,6,4]))
